var domain = 'http://miaoyou.dingfengst.com/app/v1' //正式
// var domain = 'http://localhost:8080/app/v1' //本地

function GET(Url, params) {
	return new Promise(function(resolve, reject) {
		uni.request({
			url: domain + Url,
			data: params,
			method: 'GET',
			dataType: 'json',
			header: {
				"Authorization": 'Bearer ' + uni.getStorageSync('token') || ''
			},
			success: (res) => {
				if (res.data.code == 401) {
					uni.showToast({
						title: "请先登录",
						icon: 'none'
					})
					uni.reLaunch({
						url: "/pages/login/login"
					})
				} else {
					resolve(res.data)
				}
			},
			fail(err) {
				reject(err)
			},
			complete() {}
		});
	})
}

function POST(Url, params) {
	return new Promise(function(resolve, reject) {
		uni.request({
			url: domain + Url,
			data: params,
			method: 'POST',
			dataType: 'json',
			header: {
				"Authorization": 'Bearer ' + uni.getStorageSync('token')
			},
			success: (res) => {
				if (res.data.code == 401) {
					uni.showToast({
						title: "请先登录",
						icon: 'none'
					})
					uni.reLaunch({
						url: "/pages/login/login"
					})
				} else {
					resolve(res.data)
				}
			},
			fail(err) {
				reject(err)
			},
			complete() {}
		});
	})
}
module.exports = {
	GET,
	POST,
	domain
}